package com.windbell.rest.services

import edu.fudan.mylang.pf.query.IPagedCriteria
import java.util.Collection

class PagedResult<T>{
	private Collection<T> result;
	private Integer totalRecord;
	
	def Collection<T> getResult() {
		return result
	}
	def setResult(Collection<T> r) {
		result = r
	}
	
	def Integer getTotalRecord() {
		return totalRecord
	}
	def setTotalRecord(Integer count) {
		totalRecord = count
	}
}

class PagedResults{
	def static <T,F>listAndTransform(IPagedCriteria<T> pagedCriteria, (T)=>F mapper){
		new PagedResult<F>()=>[
			it.result = pagedCriteria.list.map[mapper.apply(it)].toList
			it.totalRecord = pagedCriteria.count
		]
	}
}